package com.ueip.backend.controller;

import com.ueip.backend.service.CityService;
import com.ueip.backend.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/api/city")
public class CityController {
    @Autowired
    private CityService cityService;

    // 添加城市信息
    @PostMapping("/add")
    public  Result add(@RequestBody Map<String, String> data) {
        return cityService.add(data);
    }

    // 更新城市信息
    @PostMapping("/update")
    public Result update(@RequestBody Map<String, String> data) {
        return cityService.update(data);
    }

    // 获取所有城市信息
    @PostMapping("/get/all")
    public Result getAll() {
        return cityService.getAll();
    }

    // 获取所有省份信息
    @PostMapping("/get/provinces")
    public Result getProvinces() {
        return cityService.getProvinces();
    }

    // 获取省份下的所有城市信息
    @PostMapping("/get/city/by/pid")
    public Result getCitiesByPid(@RequestBody Map<String, String> data) {
        return cityService.getCitiesByPid(data);
    }

    // 通过城市id获取城市名称
    @PostMapping("/get/name/by/id")
    public Result getNameById(@RequestBody Map<String, String> data) {
        return cityService.getNameById(data);
    }

    // 通过城市id删除城市信息
    @PostMapping("/delete/by/id")
    public  Result deleteById(@RequestBody Map<String, String> data) {
        return cityService.deleteById(data);
    }
}
